import 'dart:io';

import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

class AdddongtaiController extends GetxController {
  //TODO: Implement AdddongtaiController

  final count = 0.obs;
  String str = '';
  final imgsList = [].obs;
  @override
  void onInit() {
    super.onInit();
  }

  //
  addImg() async {
    XFile? image = await (ImagePicker().pickImage(source: ImageSource.gallery));

    if (image != null) {
      imgsList.add(File(image.path));
    }
  }

  deleteImg(index) {
    print('删除图片');
    imgsList.removeAt(index);
    imgsList.refresh();
  }

  add() {
    if (str.isEmpty) {
      EasyLoading.showToast('正文不能为空~');
      return;
    }
    EasyLoading.show();
    Future.delayed(Duration(seconds: 2), () {
      EasyLoading.dismiss();
      EasyLoading.showToast('发布成功,请等待审核');
      Get.back();
    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {}
  void increment() => count.value++;
}
